// This code shows example usage of the OpenNetworks for Google Maps API

// Network object
var net;

function create_network(node_edge_obj) {
  // create a mapper
  map_to_latlng = new LinearCoordToLatLngMapper(1,1);
  mapper = new CoordToLatLngBoundsMapper(map_to_latlng, 0.1);
  mapType = new BlankCustomMapType('custom');
  net = new Network("map_field", node_edge_obj.nodes, node_edge_obj.edges, mapType, null, mapper);
  //net.bindEventToNodes("click", function() {alert(this.title + " " + this.getPosition())});
  net.bindEventToNodes("click", function() { centerMap(this.getMap(), this.getPosition()); }); 
  net.addControlElement(google.maps.ControlPosition.TOP_RIGHT, createCheckboxControlDiv("Show nodes", true, 'if (!this.checked) { net.hideNodes(); } else { net.showNodes(); }'));
  net.addControlElement(google.maps.ControlPosition.TOP_RIGHT, createRadioButtonControlDiv("Test button", "radio", false, 'alert("test button");'));
  net.addControlElement(google.maps.ControlPosition.TOP_RIGHT, createButtonControlDiv("Show num nodes", "", 'document.getElementById("num_nodes").innerHTML = net.Nodes.length;'));
  //net.addControlElement(google.maps.ControlPosition.TOP_RIGHT, createButtonControlDiv("Show num nodes", 'alert(net.Nodes.length);'));
  net.addControlElement(google.maps.ControlPosition.RIGHT, createTextDiv("Number of nodes", "num_nodes"));

  // write the number of edges in the network 
  //var text_div = document.getElementById("num_edges");
  //var text_div = net.map.controls[google.maps.ControlPosition.RIGHT].getAt(0);
  //text_div.innerHTML = "Number of edges: " + net.Edges.length;
  //update_text();
}
